package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.UserAnalysisInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserAnalysisMapper {

    @Select("SELECT * FROM user_analysis")
    List<UserAnalysisInfo> findAll();

    @Select("SELECT * FROM user_analysis WHERE user_id = #{userId}")
    List<UserAnalysisInfo> findByUserId(Integer userId);

    @Select("SELECT * FROM user_analysis WHERE id = #{id}")
    UserAnalysisInfo findById(Integer id);

    @Insert("INSERT INTO user_analysis(user_id, course_id, practice_range_start, practice_range_end, total_questions, correct_questions, accuracy_rate, weak_points, study_trend) " +
            "VALUES (#{userId}, #{courseId}, #{practiceRangeStart}, #{practiceRangeEnd}, #{totalQuestions}, #{correctQuestions}, #{accuracyRate}, #{weakPoints}, #{studyTrend})")
    int insert(UserAnalysisInfo info);

    @Update("UPDATE user_analysis SET " +
            "course_id = #{courseId}, practice_range_start = #{practiceRangeStart}, practice_range_end = #{practiceRangeEnd}, " +
            "total_questions = #{totalQuestions}, correct_questions = #{correctQuestions}, accuracy_rate = #{accuracyRate}, " +
            "weak_points = #{weakPoints}, study_trend = #{studyTrend}, update_time = NOW() " +
            "WHERE id = #{id}")
    int update(UserAnalysisInfo info);

    @Delete("DELETE FROM user_analysis WHERE id = #{id}")
    int deleteById(Integer id);
}
